import { fetchList } from '@/api/classify'
const classfiy = {
  state: {
    classifyList: [],
    classifyTotal: 0
  },
  getters: {
    classifyList: state => state.classifyList,
    classifyTotal: state => state.classifyTotal
  },
  mutations: {
    SET_CLASSIFYLIST: (state, classifyList) => {
      state.classifyList = classifyList
    },
    SET_CLASSIFYTOTAL: (state, total) => {
      state.classifyTotal = total
    }
  },
  actions: {
    async getClassifyList ({commit}, listQuery) {
      let res = await fetchList(listQuery)
      let items = res.data.items
      let total = res.data.total
      items.map(item => {
        item.classify_labels = []
        item.time = new Date(item.created_at).getTime()
      })
    //   items = utils.bubbleSort(items, 'time', 'reverse')
      items.map((item, index) => {
        item.classify_serial_number = index + 1
        delete item.time
      })
      commit('SET_CLASSIFYLIST', items)
      commit('SET_CLASSIFYTOTAL', total)
      return items
    }
  }
}
export default classfiy
